package ai4games_tests.soccer;

import game2dai.entities.Artefact;
import game2dai.entities.BaseEntity;
import game2dai.entityshapes.ps.PicturePS;
import game2dai.maths.Vector2D;
import processing.core.PApplet;

public class Goal extends Artefact implements Constants {

	public final Vector2D centre;
	
	public Goal(PApplet papp, Team team, Pitch pitch, int pitchSide){
		double x = (pitchSide == 0) ? KEEPER_TEND_DIST : PITCH_LENGTH - KEEPER_TEND_DIST;
		double y = PITCH_WIDTH/2;
		pos.set(x,y);
		centre = new Vector2D(x,y);

		this.renderer( new GoalRenderer(papp, team, GOAL_WIDTH, GOAL_DEPTH));

	}
	
	public class GoalRenderer extends PicturePS {

		Team team;
		
		float depth = 0;
		float width = 0;
		
		public GoalRenderer(PApplet papp, Team team, double width, double depth){
			super(papp);
			this.team = team;
			this.width = (float) width;
			this.depth = (float) depth;
		}
		
		
		@Override
		public void draw(BaseEntity owner, float posX, float posY, float velX,
				float velY, float headX, float headY) {
			app.pushStyle();
			app.pushMatrix();
			app.translate(posX, posY);
			
			app.rectMode(PApplet.CENTER);

			app.noFill();
			app.stroke(team.teamColors[0]);
			app.strokeWeight(2.0f);
			app.rect(0,0,depth, width);

			app.popMatrix();
			app.popStyle();	
		}
	}
}
